$(function () {
    var isYgBmfwSetted = $("#isYgBmfwSetted").val();
    var ygId = $("#bmfw-ygid").val();
    var treeUrl = "/organ/bmfw/get_treejson";
    var searchUrl = '/sys/wzbm/search?fw=1';
    if(isYgBmfwSetted == 'true') {
        searchUrl = '/sys/wzbm/searchByYg';
        treeUrl = "/organ/bmfw/get_treejsonbyyg?ygId="+ygId;
    }
    $("[name='search-wzbm-tree-yg']").tree({
        url: $.webPath()+treeUrl,
        onClick: function (node) {
            if(node.attributes.level == 3){
                $(searchGrid).datagrid({
                    url:$.webPath()+"/sys/wzbm/get_gridjson",
                    fitColumns:true,
                    fit:true,
                    pageNumber:1,
                    queryParams: {"level": node.attributes.level, "wzbmId": node.id.split(":")[0]},
                    columns: [
                        [
                            {title: "名称", field: "name", width: 100},
                            {title: "编码", field: "oldcode", width: 100},
                            {title: "编码(新)", field: "code", width: 100},
                            {title: "规格型号", field: "ggxh", width: 100},
                            {title: "规格简称", field: "ggjc", width: 100},
                            {title: "材质", field: "cz", width: 100},
                            {title: "单位", field: "dw", width: 100},
                            {title: "是否报价", field: "sfbj", width: 100},
                            {title: "所属品名", field: "pm_name", width: 100}
                        ]
                    ]
                });
            }
            else{
                $("[name='search-wzbm-tree-yg']").tree("expand",node.target);
            }
        }
    });

    var searchGrid = $("#search-wzbm-grid-yg").datagrid({
        columns: [
            [
                {title: "名称", field: "name", width: 100},
                {title: "编码", field: "oldcode", width: 100},
                {title: "编码(新)", field: "code", width: 100},
                {title: "规格型号", field: "ggxh", width: 100},
                {title: "规格简称", field: "ggjc", width: 100},
                {title: "材质", field: "cz", width: 100},
                {title: "单位", field: "dw", width: 100},
                // {title: "是否报价", field: "sfbj", width: 100},
                {title: "所属品名", field: "pm_name", width: 100}
            ]
        ]
    });

    $("#search-wzbm-toolbar-yg :button").click(function () {
        //alert(searchUrl);
        $('#search-wzbm-grid-yg').datagrid({
            url:$.webPath() + searchUrl,
            pageNumber:1,
            queryParams:{
                name: $('#mc-yg').val(),
                code: $('#code-yg').val(),
                cz:$("#cz-yg").val(),
                ggxh: $("#ggxh-yg").val()
            },
            columns:[
                [
                    {title:"名称", field:"name", width:100},
                    {title: "编码", field: "oldcode", width: 100},
                    {title: "编码(新)", field: "code", width: 100},
                    {title:"规格型号", field:"ggxh", width:100},
                    {title:"规格简称", field:"ggjc", width:100},
                    {title:"材质", field:"cz", width:100},
                    {title:"单位", field:"dw", width:100},
                    {title:"是否报价", field:"sfbj", width:100, formatter:function (value, row, index) {
                        return value ? '是' : '否'
                    }},
                    {title:"所属品名", field:"pm_name", width:100}
                ]
            ]
        });
    });
})

